package com.dushibao.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dushibao.admin.mapper.MenuMapper;
import com.dushibao.admin.model.Menu;
import com.dushibao.admin.service.IMenuService;
import com.dushibao.admin.vo.request.MenuModelPageRequest;
import com.dushibao.page.PageImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 *  菜单服务实现类
 *
 * @author zqd
 * @date 2021-12-07 08:28:35
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Autowired
    MenuMapper menuMapper;

    @Override
    public List<Menu> selectTreeMenus(MenuModelPageRequest pageRequest) {
        return menuMapper.selectTreeMenus(pageRequest);
    }

    @Override
    public PageImpl<Menu> selectPageImpl(MenuModelPageRequest pageRequest) {

        List<Menu> records = menuMapper.selectPages(pageRequest);

        int total = menuMapper.selectCount(pageRequest);

        PageImpl<Menu> iPage = new PageImpl<>();

        iPage.setCurrent(pageRequest.getCurrent());
        iPage.setSize(pageRequest.getPageSize());

        iPage.setTotal(total);

        iPage.setRecords(records);

        return iPage;
    }

    @Override
    public List<Menu> findTreeMenu() {
        return menuMapper.findTreeMenu();
    }

    @Override
    public List<Menu> findAdminMenus(Long adminId) {
        return menuMapper.findAdminMenus(adminId);
    }

    @Override
    public List<Menu> findAdminMenuList(Long adminId) {
        return menuMapper.findAdminMenuList(adminId);
    }
}
